package random

import (
	"math/rand"
)

type Random struct {
}

func New() Random {
	return Random{}
}

func (R Random) RandomStringOnlyNum(num int) (randomRes RandomResStr) {
	chars := "0123456789"
	return RandomResStr(R.RandomStr(num, chars))
}

func (R Random) RandomString(num int) (randomRes RandomResStr) {
	chars := "ABCDEFGHIJKMNPQRSTUVWXYZabcdefghijkmnpqrstuvwxyz0123456789"
	return RandomResStr(R.RandomStr(num, chars))
}

func (R Random) RandomStr(num int, chars string) (res string) {
	if num <= 0 {
		return ""
	}
	charsLen := len(chars)
	for i := 0; i < num; i++ {
		randIndex := rand.Intn(charsLen)
		res += chars[randIndex : randIndex+1]
	}
	return res
}
